#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define PII pair<int, int>

void solve()
{
    int n, k, ans = 0; cin >> n >> k;
    string a, b; cin >> a >> b;
    for (int i = n - 1, p = n - 1; i >= 0; --i) {
        p = min(p, i);
        while (p >= 0 && b[i] != a[p]) --p;
        ans = max(ans, i - p);
        if (p < 0 || ans > k) {
            cout << -1 << endl;
            return;
        }
    }
    cout << ans << endl;
    while (ans--) {
        for (int i = n - 1, p = n - 1; i > 0; --i) {
            p = min(p, i);
            while (p >= 0 && b[i] != a[p]) --p;
            if (i > p) a[i] = a[i - 1];
        }
        cout << a << endl;
    }
}

signed main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t; cin >> t;
    while (t--) solve();
    return 0;
}

//100
//5 5 abbbb bbbbb
//5 5 abbbb bbbba
//5 5 abaaa aaaab
//5 5 abaaa abbbb


